﻿#include "userdataformate.h"
#include <QVariantMap>
#include <QMapIterator>
#include <QUuid>
#include <QDebug>
extern ST_PatientMsg variantMapToPatientMsg(QVariantMap vMap)
{
    ST_PatientMsg st_PatientMsg;
    if(vMap.contains("userName"))
        st_PatientMsg.userName = vMap.value("userName").toString();
    if(vMap.contains("userPhone"))
        st_PatientMsg.userPhone = vMap.value("userPhone").toString();
    if(vMap.contains("sex"))
        st_PatientMsg.sex = vMap.value("sex").toInt();
    if(vMap.contains("age"))
        st_PatientMsg.age = vMap.value("age").toInt();
    if(vMap.contains("weight"))
        st_PatientMsg.weight = vMap.value("weight").toInt();
    if(vMap.contains("ID"))
        st_PatientMsg.ID = vMap.value("ID").toInt();
    if(vMap.contains("height"))
        st_PatientMsg.height = vMap.value("height").toInt();
    if(vMap.contains("remarkMessage"))
        st_PatientMsg.remarkMessage = vMap.value("remarkMessage").toString();

    return st_PatientMsg;
}
//评估记录
extern ST_EvaluateRecord variantMapToEvaluateRecord(QVariantMap vMap)
{
    ST_EvaluateRecord st_EvaluateRecord;
    if(vMap.contains("ID"))
        st_EvaluateRecord.ID = vMap.value("reportDate").toInt();
    if(vMap.contains("evaluateDate"))
        st_EvaluateRecord.evaluateDate = vMap.value("evaluateDate").toDateTime();
    if(vMap.contains("evaluateDuration"))
        st_EvaluateRecord.evaluateDuration = vMap.value("evaluateDuration").toInt();
    if(vMap.contains("resistance"))
        st_EvaluateRecord.resistance = vMap.value("resistance").toInt();
    if(vMap.contains("maxAngle"))
        st_EvaluateRecord.maxAngle = vMap.value("maxAngle").toString();
	if(vMap.contains("evaluateDateStr"))
        st_EvaluateRecord.evaluateDateStr = vMap.value("evaluateDateStr").toString();
    return st_EvaluateRecord;
}
//评估报告
extern ST_EvaluateReport variantMapToEvaluateReport(QVariantMap vMap)
{
    ST_EvaluateReport st_EvaluateReport;
    if(vMap.contains("ID"))
        st_EvaluateReport.ID = vMap.value("ID").toInt();
    if(vMap.contains("reportDate"))
        st_EvaluateReport.reportDate = vMap.value("reportDate").toDateTime();
    if(vMap.contains("name"))
        st_EvaluateReport.name = vMap.value("name").toString();
    if(vMap.contains("sex"))
        st_EvaluateReport.sex = vMap.value("sex").toInt();
    if(vMap.contains("phoneNumber"))
        st_EvaluateReport.phoneNumber = vMap.value("phoneNumber").toString();
    if(vMap.contains("height"))
        st_EvaluateReport.height = vMap.value("height").toInt();
    if(vMap.contains("age"))
        st_EvaluateReport.age = vMap.value("age").toInt();
    if(vMap.contains("remark"))
        st_EvaluateReport.remark = vMap.value("remark").toString();
    if(vMap.contains("resistance"))
        st_EvaluateReport.resistance = vMap.value("resistance").toInt();
    if(vMap.contains("evaluateDuration"))
        st_EvaluateReport.evaluateDuration = vMap.value("evaluateDuration").toInt();
    if(vMap.contains("frontMaxAngle"))
        st_EvaluateReport.frontMaxAngle = vMap.value("frontMaxAngle").toInt();
    if(vMap.contains("backMaxAngle"))
        st_EvaluateReport.backMaxAngle = vMap.value("backMaxAngle").toInt();
    if(vMap.contains("leftMaxAngle"))
        st_EvaluateReport.leftMaxAngle = vMap.value("leftMaxAngle").toInt();
    if(vMap.contains("rightMaxAngle"))
        st_EvaluateReport.rightMaxAngle = vMap.value("rightMaxAngle").toInt();
	 if(vMap.contains("reportDateStr"))
        st_EvaluateReport.reportDateStr = vMap.value("reportDateStr").toString();
    if(vMap.contains("backGroundPixmapPath"))
        st_EvaluateReport.backGroundPixmapPath = vMap.value("backGroundPixmapPath").toString();
   return st_EvaluateReport;
}

//训练报告
extern ST_TrainReport variantMapToTrainReport(QVariantMap vMap)
{
    ST_TrainReport st_TrainReport;
    if(vMap.contains("ID"))
        st_TrainReport.ID = vMap.value("ID").toInt();
    if(vMap.contains("userName"))
        st_TrainReport.userName = vMap.value("userName").toString();
    if(vMap.contains("sex"))
        st_TrainReport.sex = vMap.value("sex").toInt();
    if(vMap.contains("userPhone"))
        st_TrainReport.userPhone = vMap.value("userPhone").toString();
    if(vMap.contains("height"))
        st_TrainReport.height = vMap.value("height").toInt();
    if(vMap.contains("age"))
        st_TrainReport.age = vMap.value("age").toInt();
    if(vMap.contains("remark"))
        st_TrainReport.remark = vMap.value("remark").toString();
    if(vMap.contains("trainTime"))
        st_TrainReport.trainTime = vMap.value("trainTime").toInt();
    if(vMap.contains("resistance"))
        st_TrainReport.resistance = vMap.value("resistance").toInt();
    if(vMap.contains("range"))
        st_TrainReport.range = vMap.value("range").toInt();
    if(vMap.contains("trainDifficulty"))
        st_TrainReport.trainDifficulty = vMap.value("trainDifficulty").toInt();
    if(vMap.contains("gameplay"))
        st_TrainReport.gameplay = vMap.value("gameplay").toString();
    if(vMap.contains("direction"))
        st_TrainReport.direction = vMap.value("direction").toInt();
    if(vMap.contains("game"))
        st_TrainReport.game = vMap.value("game").toInt();
     if(vMap.contains("reportDate"))
        st_TrainReport.reportDate = vMap.value("reportDate").toDateTime();
	if(vMap.contains("reportDateStr"))
        st_TrainReport.reportDateStr = vMap.value("reportDateStr").toString();
    if(vMap.contains("backGroundPixmapPath"))
        st_TrainReport.backGroundPixmapPath = vMap.value("backGroundPixmapPath").toString();
    return st_TrainReport;
}

//训练记录
extern ST_TrainRecord variantMapToTrainRecord(QVariantMap vMap)
{
    ST_TrainRecord st_TrainRecord;
    if(vMap.contains("ID"))
        st_TrainRecord.ID = vMap.value("ID").toInt();
    if(vMap.contains("trainingDate"))
        st_TrainRecord.trainingDate = vMap.value("trainingDate").toDateTime();
    if(vMap.contains("trainingDuration"))
        st_TrainRecord.trainingDuration = vMap.value("trainingDuration").toInt();
    if(vMap.contains("resistance"))
        st_TrainRecord.resistance = vMap.value("resistance").toInt();
    if(vMap.contains("difficulty"))
        st_TrainRecord.difficulty = vMap.value("difficulty").toString();
    if(vMap.contains("score"))
        st_TrainRecord.score = vMap.value("score").toInt();
    if(vMap.contains("gameplay"))
        st_TrainRecord.gameplay = vMap.value("gameplay").toString();

    return st_TrainRecord;
}
extern QVariantMap patientMsgToVariantMap(ST_PatientMsg st_PatientMsg)
{
    QVariantMap vMap;

    vMap.insert("userName",st_PatientMsg.userName);
    vMap.insert("userPhone",st_PatientMsg.userPhone);
    vMap.insert("sex",st_PatientMsg.sex);
    vMap.insert("age",st_PatientMsg.age);
    vMap.insert("weight",st_PatientMsg.weight);
    vMap.insert("ID",st_PatientMsg.ID);
    vMap.insert("height",st_PatientMsg.height);
    vMap.insert("remarkMessage",st_PatientMsg.remarkMessage);

    return vMap;
}

//训练报告
extern QVariantMap trainReportToVariantMap(ST_TrainReport st_TrainReport)
{
    QVariantMap vMap;
    //添加UUID
    QUuid id = QUuid::createUuid();
    QString strId = id.toString(QUuid::Id128);
    vMap.insert("UUID",strId);
    vMap.insert("ID",st_TrainReport.ID);
    vMap.insert("userName",st_TrainReport.userName);
    vMap.insert("sex",st_TrainReport.sex);
    vMap.insert("userPhone",st_TrainReport.userPhone);
    vMap.insert("height",st_TrainReport.height);
    vMap.insert("age",st_TrainReport.age);
    vMap.insert("remark",st_TrainReport.remark);
    vMap.insert("resistance",st_TrainReport.resistance);
    vMap.insert("range",st_TrainReport.range);
    vMap.insert("trainDifficulty",st_TrainReport.trainDifficulty);
    vMap.insert("gameplay",st_TrainReport.gameplay);
    vMap.insert("direction",st_TrainReport.direction);
    vMap.insert("game",st_TrainReport.game);
    vMap.insert("trainTime",st_TrainReport.trainTime);
    vMap.insert("reportDate",st_TrainReport.reportDate);
	st_TrainReport.reportDateStr = st_TrainReport.reportDate.toString("yyyy-MM-dd hh:mm:ss");
    vMap.insert("reportDateStr",st_TrainReport.reportDateStr);
    vMap.insert("backGroundPixmapPath",st_TrainReport.backGroundPixmapPath);
    return vMap;
}

//训练记录
extern QVariantMap trainRecordToVariantMap(ST_TrainRecord st_TrainRecord)
{
    QVariantMap vMap;
    //添加UUID
    QUuid id = QUuid::createUuid();
    QString strId = id.toString(QUuid::Id128);
    vMap.insert("UUID",strId);
    vMap.insert("ID",st_TrainRecord.ID);
    vMap.insert("trainingDate",st_TrainRecord.trainingDate);
    vMap.insert("trainingDuration",st_TrainRecord.trainingDuration);
    vMap.insert("resistance",st_TrainRecord.resistance);
    vMap.insert("difficulty",st_TrainRecord.difficulty);
    vMap.insert("score",st_TrainRecord.score);
    vMap.insert("gameplay",st_TrainRecord.gameplay);
	st_TrainRecord.trainingDateStr = st_TrainRecord.trainingDate.toString("yyyy-MM-dd hh:mm:ss");
    vMap.insert("trainingDateStr",st_TrainRecord.trainingDateStr);
    return vMap;
}

//评估记录
extern QVariantMap evaluateRecordToVariantMap(ST_EvaluateRecord st_EvaluateRecord)
{
    QVariantMap vMap;
    //添加UUID
    QUuid id = QUuid::createUuid();
    QString strId = id.toString(QUuid::Id128);
    vMap.insert("UUID",strId);
    vMap.insert("ID",st_EvaluateRecord.ID);
    vMap.insert("evaluateDate",st_EvaluateRecord.evaluateDate);
    vMap.insert("evaluateDuration",st_EvaluateRecord.evaluateDuration);
    vMap.insert("resistance",st_EvaluateRecord.resistance);
    vMap.insert("maxAngle",st_EvaluateRecord.maxAngle);
	st_EvaluateRecord.evaluateDateStr = st_EvaluateRecord.evaluateDate.toString("yyyy-MM-dd hh:mm:ss");
    vMap.insert("evaluateDateStr",st_EvaluateRecord.evaluateDateStr);
    return vMap;
}

//评估报告
extern QVariantMap evaluateReportToVariantMap(ST_EvaluateReport st_EvaluateReport)
{
    QVariantMap vMap;
    //添加UUID
    QUuid id = QUuid::createUuid();
    QString strId = id.toString(QUuid::Id128);
    vMap.insert("UUID",strId);
    vMap.insert("ID",st_EvaluateReport.ID);
    vMap.insert("reportDate",st_EvaluateReport.reportDate);
    vMap.insert("name",st_EvaluateReport.name);
    vMap.insert("sex",st_EvaluateReport.sex);
    vMap.insert("phoneNumber",st_EvaluateReport.phoneNumber);
    vMap.insert("height",st_EvaluateReport.height);
    vMap.insert("age",st_EvaluateReport.age);
    vMap.insert("remark",st_EvaluateReport.remark);
    vMap.insert("resistance",st_EvaluateReport.resistance);
    vMap.insert("evaluateDuration",st_EvaluateReport.evaluateDuration);
    vMap.insert("frontMaxAngle",st_EvaluateReport.frontMaxAngle);
    vMap.insert("backMaxAngle",st_EvaluateReport.backMaxAngle);
    vMap.insert("leftMaxAngle",st_EvaluateReport.leftMaxAngle);
    vMap.insert("rightMaxAngle",st_EvaluateReport.rightMaxAngle);
    vMap.insert("backGroundPixmapPath",st_EvaluateReport.backGroundPixmapPath);
	st_EvaluateReport.reportDateStr = st_EvaluateReport.reportDate.toString("yyyy-MM-dd hh:mm:ss");
    vMap.insert("reportDateStr",st_EvaluateReport.reportDateStr);
    return vMap;
}


